import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

class MovieManagementSystem {
    private List<Movie> movies = new ArrayList<>();

    public void addMovie(Movie movie) {
        movies.add(movie);
        System.out.println("影片《" + movie.getName() + "》已添加");
    }

    public boolean updateMovie(String movieName, Movie updatedMovie) {
        Movie movie = findMovieByName(movieName);
        if (movie == null) {
            System.out.println("未找到影片: " + movieName);
            return false;
        }

        movie = updatedMovie;
        System.out.println("影片《" + movieName + "》已更新");
        return true;
    }

    public boolean deleteMovie(String movieName) {
        Movie movie = findMovieByName(movieName);
        if (movie == null) {
            System.out.println("未找到影片: " + movieName);
            return false;
        }
        if (movie.isShowing()) {
            System.out.println("错误: 影片《" + movieName + "》正在上映，无法删除");
            return false;
        }

        movies.remove(movie);
        System.out.println("影片《" + movieName + "》已删除");
        return true;
    }

    public List<Movie> listAllShowingMovies() {
        return movies.stream()
                .filter(Movie::isShowing)
                .collect(Collectors.toList());
    }

    public List<Movie> searchMovies(String name, String director, String actor) {
        return movies.stream()
                .filter(movie -> (name == null || movie.getName().contains(name)) &&
                        (director == null || movie.getDirector().contains(director)) &&
                        (actor == null || movie.getActors().stream().anyMatch(a -> a.contains(actor))))
                .collect(Collectors.toList());
    }

    private Movie findMovieByName(String name) {
        return movies.stream()
                .filter(m -> m.getName().equals(name))
                .findFirst()
                .orElse(null);
    }
}